//
//  UIBarButtonItem+MYBarButtonItem.m
//  微博app--OC
//
//  Created by xmy on 16/8/31.
//  Copyright © 2016年 xmy. All rights reserved.
//

#import "UIBarButtonItem+MYBarButtonItem.h"

@implementation UIBarButtonItem (MYBarButtonItem)
+ (instancetype)barWithImageName:(NSString *)string title:(NSString *)title target:(id)target action:(SEL)action;{
    
    //创建按钮
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    //设置btn的属性
    //图片
    [btn setImage:[UIImage imageNamed:string] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted",string]] forState:UIControlStateHighlighted];
    //文字
    [btn setTitle:title forState:UIControlStateNormal];
    //文字颜色
    [btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor orangeColor] forState:UIControlStateHighlighted];
    //字体大小
    btn.titleLabel.font = [UIFont systemFontOfSize:14];
    
    //点击事件
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];

    [btn sizeToFit];
    
    UIBarButtonItem *bar = [[UIBarButtonItem alloc]initWithCustomView:btn];
    
    return bar;

}
@end
